﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            text3();
        }
        //用户输入正方形边长，用*打印出实心正方形。
        static void text1()
        {
            Console.WriteLine("请输入正方形的边长");
            int num = int.Parse(Console.ReadLine());
            string[,] arr = new string[num, num];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = "*";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
        //九九乘法表
        static void text2()
        {
            string[,] arr = new string[9, 9];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    arr[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1) + "\t";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }

        }
        //用户输入正方形边长，用*打印出空心正方形。
        static void text3()
        {
            Console.WriteLine("请输入正方形的边长");
            int num = int.Parse(Console.ReadLine());
            string[,] arr = new string[num, num];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (i == 0 || i == arr.GetLength(0) - 1)
                    {
                        arr[i, j] = "*";
                    }
                    else
                    {
                        if (j == 0 || j == arr.GetLength(1) - 1)
                        {
                            arr[i, j] = "*";
                        }
                        else
                        {
                            arr[i, j] = " ";
                        }
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
        }
        //打印菱形
        static void text4()
        {
            Console.WriteLine("请输入菱形的边长（奇数）");
            int a = int.Parse(Console.ReadLine());

            string[,] arr = new string[a * 2, a * 2];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (i <= a && j > a - i && j < a + i || a < i && j > i - a && j <= 3 * a - 1 - i)
                    {
                        arr[i, j] = "*";
                    }
                    else
                    {
                        arr[i, j] = " ";
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
        }
        //在 Main 方法中创建一个字符串类型的数组，
        //并存入 5 个值，然后将数组中下标是偶数的元素输出。
        static void text5()
        {
            string[] arr = { "a", "b", "c", "d", "e" };
            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(arr[i]);
                }
            }
        }
        //如果一个数组保存元素是有序的（从大到小）
        //向这个数组中插入一个数，使得插入后的数组元素仍然保持有序。
        static void text6()
        {
            int[] arr = { 10, 20, 30, 40, 50 };
            Array.Sort(arr);
            Array.Reverse(arr);
            foreach (var item in arr)
            {
                Console.Write(item + "\t");
            }
            Console.WriteLine();
            int[] ayy = new int[6];
            ayy[5] = 25;
            for (int i = 0; i < 5; i++)
            {
                ayy[i] = arr[i];
            }
            Array.Sort(ayy);
            Array.Reverse(ayy);
            foreach (var item in ayy)
            {
                Console.Write(item + "\t");
            }
        }
        //杨辉三角
        static void text7()
        {

        }
    }
}


